package com.zt.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zt.mapper.CheckitemMapper;
import com.zt.pojo.Checkitem;
import com.zt.pojo.vo.CheckitemVo;
import com.zt.service.CheckitemService;
import com.zt.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 不.凌
* @description 针对表【t_checkitem】的数据库操作Service实现
* @createDate 2024-11-17 19:36:06
*/
@Service
public class CheckitemServiceImpl implements CheckitemService{
    @Autowired
    private CheckitemMapper checkitemMapper;
    /**
     * 分页模糊查询
     * @param checkitemVo
     * @return
     */
    @Override
    public Result findPage(CheckitemVo checkitemVo) {
        PageHelper.startPage(checkitemVo.getCurrentPage(), checkitemVo.getPageSize());
        List<Checkitem> checkitemList = checkitemMapper.findPage(checkitemVo);
        PageInfo<Checkitem> pageInfo = new PageInfo<>(checkitemList);
        return Result.success("查询成功",pageInfo);
    }

    /**
     * 添加检查项
     * @param checkitem
     * @return
     */
    @Override
    public Result add(Checkitem checkitem) {
        try {
            int insert = checkitemMapper.add(checkitem);
            return Result.success("添加成功",insert);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("添加失败");
    }

    /**
     * 删除检查项
     * @param id
     * @return
     */
    @Override
    public Result delete(Integer id) {
        try {
            int delete = checkitemMapper.delete(id);
            return Result.success("删除成功",delete);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("删除失败");
    }

    /**
     * 修改检查项
     * @param checkitem
     * @return
     */
    @Override
    public Result update(Checkitem checkitem) {
        try {
            int update = checkitemMapper.update(checkitem);
            return Result.success("修改成功",update);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("修改失败");
    }

    /**
     * 根据id查询检查项
     * @param id
     * @return
     */
    @Override
    public Result findById(Integer id) {
        Checkitem checkitem = checkitemMapper.findById(id);
        return Result.success("查询成功",checkitem);
    }

    /**
     * 查询所有检查项
     * @return
     */
    @Override
    public Result findAll() {
        List<Checkitem> all = checkitemMapper.findAll();
        return Result.success("查询成功",all);
    }
}




